package mo.tags.design;

import java.util.Stack;

class MinStack {

    private final Stack<Integer> min;
    private final Stack<Integer> elements;

    public MinStack() {
        min = new Stack<>();
        elements = new Stack<>();
    }
    
    public void push(int val) {
        elements.push(val);
        if (min.isEmpty() || min.peek() > val) {
            min.push(val);
        } else {
            min.push(min.peek());
        }
    }
    
    public void pop() {
        elements.pop();
        min.pop();
    }
    
    public int top() {
        return elements.peek();
    }
    
    public int getMin() {
        return min.peek();
    }
}